package Model;

/**
 * Stores data for each player in the game
 * @author Phillip Pecher
 */

public class Player implements Comparable<Player> {

	private String race; 
	private String color;
	private int money;
	private int food;
	private int energy;
	private int ore;

	private int score;
	private String name;
	private Mule mule;
	private boolean isHuman;
	private boolean possessMule;

	/**
	 * default constructor for Player class the view.setupscreen classes will
	 * set all the variables for a Player
	 */
	public Player() {
		super();
	}

	/**
	 * Player constructor for loading from database.
	 * @param race2
	 * @param color2
	 * @param money2
	 * @param food2
	 * @param energy2
	 * @param ore2
	 * @param name2
	 * @param possessMule2
	 * @param isHuman2
	 * @param score2
	 * @param mID
	 */
	public Player(String race2, String color2, int money2, int food2,
			int energy2, int ore2, String name2, boolean possessMule2,
			boolean isHuman2, int score2, Mule mID) {
		this.race = race2;
		color = color2;
		money = money2;
		food = food2;
		energy = energy2;
		ore = ore2;
		name = name2;
		possessMule = possessMule2;
		isHuman = isHuman2;
		score = score2;
		mule = mID;
		
	}

	/**
	 * 
	 * @param cost: cost of item(s) player is trying to buy
	 * @return: true if he can afford it, false otherwise
	 */
	public boolean sufficientFunds(int cost) {
		if (money >= cost) {
			return true;
		}

		else {
			return false;
		}

	}

	/**
	 * Getter for the mule
	 * @return Mule mule
	 */
	public Mule getMule() {
		return mule;
	}

	/**
	 * setter for mule data type
	 * @param m: the mule
	 */
	public void setMule(Mule m) {
		mule = m;
	}

	/**
	 * getter for possessMule field
	 * @return boolean: whether or not the player possesses a mule
	 */
	public boolean getPossessMule() {
		return possessMule;
	}

	/**
	 * setter for possessMule field
	 * @param bool: we update possessMule t this value
	 */
	public void setPossessMule(boolean bool) {
		possessMule = bool;
	}

	/**
	 * Getter for current amount of money
	 * @return int money
	 */
	public int getMoney() {
		return money;
	}

	/**
	 * Setter for money
	 * @param int money
	 */
	public void setMoney(int money) {
		this.money = money;
	}

	/**
	 * Getter for amount of food
	 * @return int food
	 */
	public int getFood() {
		return food;
	}

	/**
	 * Setter for amount of food
	 * @param int food
	 */
	public void setFood(int food) {
		this.food = food;
	}

	/**
	 * increment food field
	 * @param quantity: integer food
	 */
	public void incrementFood(int quantity) {
		food = food + quantity;
	}

	/**
	 * Getter for amount of energy
	 * @return int: energy field
	 */
	public int getEnergy() {
		return energy;
	}

	/**
	 * Setter for amount of energy
	 * @param int: energy
	 */
	public void setEnergy(int energy) {
		this.energy = energy;
	}

	/**
	 * increment energy field
	 * @param quantity: integer food
	 */
	public void incrementEnergy(int quantity) {
		energy = energy + quantity;
	}

	/**
	 * Setter for amount of ore
	 * @return int: ore
	 */
	public int getOre() {
		return ore;
	}

	/**
	 * Setter for amount of ore
	 * @param int ore
	 */
	public void setOre(int ore) {
		this.ore = ore;
	}

	/**
	 * increment ore field
	 * @param quantity: integer ore
	 */
	public void incrementOre(int quantity) {
		ore = ore + quantity;
	}

	/**
	 * decrement energy by 1 unit
	 */
	public void decrementEnergy() {
		energy = energy - 1;
	}

	/**
	 * Getter for name
	 * @return String: name
	 */
	public String getName() {
		return name;
	}

	/**
	 * Setter for name
	 * @param String
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * Getter for race
	 * @return String race
	 */
	public String getRace() {
		return race;
	}

	/**
	 * Setter for race
	 * @param String: myRace
	 */
	public void setRace(String myRace) {
		this.race = myRace;
		if (this.race == "FLAPPER") {
			this.money = 1600;
		}

		else if (this.race == "HUMAN") {
			this.money = 800;
		}

		else {
			this.money = 1000;
		}

		// set food and energy quantities (BEGINNER SETTING)
		this.food = 8;
		this.energy = 4;

		// set possessMule to False (player must go to store to hold one)
		possessMule = false;

	}

	/**
	 * Getter for color
	 * @return String color
	 */
	public String getColor() {
		return color;
	}

	/**
	 * Setter for color
	 * @param String color
	 */
	public void setColor(String color) {
		this.color = color;
	}

	/**
	 * Setter for isHuman field
	 * @param boolean b
	 */
	public void setIsHuman(boolean b) {
		this.isHuman = b;
	}

	/**
	 * Getter for isHuman field
	 * @return boolean isHuman
	 */
	public boolean isHuman() {
		return isHuman;
	}

	/**
	 * Getter for score
	 * @return score
	 */
	public int getScore() {
		return score;
	}

	/**
	 * Changes the amount of money in a player's account
	 * @param int amount
	 */
	public void addMoney(int amount) {
		money = money + amount;
	}

	/**
	 * subtracts money from a player's account
	 * @param amount
	 */
	public void subtractMoney(int amount) {
		money = money - amount;

	}

	/**
	 * Overrides the default compareTo method. Compares player objects based on
	 * the amount of money they currently have.
	 * 
	 * @param Player
	 */
	@Override
	public int compareTo(Player o) {

		Integer money2 = (Integer) o.getMoney();
		return ((Integer) money).compareTo(money2);
	}

	/**
	 * Returns the boolean possessMule as a string "1" or "0"
	 * @return "1" or "0"
	 */
	public String stringGetPossessMule() {
		if (possessMule) {
			return "1";
		}

		else
			return "0";
	}

	/**
	 * Setter for score
	 * @return void
	 */
	public void setScore(int i) {
		this.score = i;

	}

}